#include <omp.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[])
{
    int i, n;
    int *arr;
    double startTime, endTime;
    printf("Please input the size of array\n");
    n = 100;
    arr = (int *)malloc(sizeof(int) * n);
    printf("Please input the elements of array\n");
    for(i=0;i<n;i++)
        arr[i] = rand();
    startTime = omp_get_wtime();
    //使用OpenMP实现
    #pragma omp parallel for
    for(i=0;i<n-1;i++){
        //偶数放后面
        if(arr[i] % 2 == 0){
            int j = i + 1;
            while(j < n){
                if(arr[j] % 2 != 0){
                    int tmp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = tmp;
                    break;
                }
                j++;
            }
        }
    }
    endTime = omp_get_wtime();
    printf("The sorted array is\n");
    for(i=0;i<n;i++)
        printf("%d ", arr[i]);
    printf("\nThe time of sorting is %f\n", endTime - startTime);
    return 0;
}